package com.example.nongye.adapter;

import android.text.TextUtils;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.nongye.R;
import com.example.nongye.http.api.BillListApi;
import com.example.nongye.utils.StringUtils;

import java.util.List;


public class BillListAdapter extends BaseQuickAdapter<BillListApi.Response, BaseViewHolder> {


    public BillListAdapter(@Nullable List<BillListApi.Response> data) {
        super(R.layout.item_bill, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, BillListApi.Response bill) {
        baseViewHolder.setText(R.id.tv_title, bill.getItem());
        if (!TextUtils.isEmpty(bill.getCreateDate())) {
            baseViewHolder.setText(R.id.tv_time, bill.getCreateDate().replace("T", " "));
        }
        TextView tvAmount = baseViewHolder.getView(R.id.tv_amount);
        if (null != bill.getAmount()) {
            if (bill.getAmount() > 0) {
                tvAmount.setTextColor(getContext().getResources().getColor(R.color.colorAccent));
                baseViewHolder.setText(R.id.tv_amount, "+" + StringUtils.numberFormat(bill.getAmount()));
            } else {
                tvAmount.setTextColor(getContext().getResources().getColor(R.color.color_333));
                baseViewHolder.setText(R.id.tv_amount, StringUtils.numberFormat(bill.getAmount()));
            }
        }
        if (null != bill.getBalance()) {
            baseViewHolder.setText(R.id.tv_balance, "余额：" + StringUtils.numberFormat(bill.getBalance()));
        }
    }
}
